import { Server } from "colyseus";
import { createServer } from "http";
import express from "express";
import { MyRoom } from "./rooms/MyRoom";
import routes from "./routes/routes"; // API 路由

const app = express();
const port = 2567;
const server = createServer(app);
const gameServer = new Server({ server });

// 预创建多个地图房间
const MAPS = ["forest", "desert", "city", "dungeon", "castle"];
MAPS.forEach(map => {
    gameServer.define(map, MyRoom).enableRealtimeListing();
    console.log(`房间 ${map} 已创建`);
});

// 绑定 API 端点
app.use("/auth", routes); // 现在可以访问 /auth/register, /auth/login

// 启动 Colyseus 服务器
gameServer.listen(port);
console.log(`Colyseus 服务器运行在端口 ${port}`);
